import '../scss/reset.css';
import '../scss/admin_common.css';
import '../scss/admin_manage_prod.css';
import '../layui/css/layui.css';

import './jquery.js';

; (() => {

  let $table = $('#js-click-table');

  var init = () => {
    bindEvent();
  }
  init();

  function bindEvent() {
    $table.click(deleteProduct);
  }

  function deleteProduct(e) {
    console.log(e);
    let target = e.target || e.srcElement;

    if ($(target).prop('id') === 'deleteBtn') {
      let isDelete = confirm("删除是不可恢复的，你确认要删除吗？"),
          pid = $(target).attr('data-id');
          console.log(pid)
      if (isDelete) {
        $.ajax({
          url: 'http://localhost:3005/admin/post-delete-product',
          type: 'POST',
          data: {
            pid: pid
          },
          dataType: 'JSON',
          success: (res) => {
            alert('删除成功!');
            location.reload();
          },
          error: (err) => [
            console.log(err)
          ]
        });
      }
    }

  }
})();